package com.core.util;

import java.sql.Connection;
import java.sql.Date;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class DBConnection {
	private String username = "root", password = "12345";
	private String database = "dsp_development";
	//ResultSet rs;
	private static Connection conn;

	private DBConnection()
	{
		//String url = "jdbc:datadirect:sqlserver://127.0.0.1:1433;databaseName="+database;
		String url = "jdbc:mysql://localhost:3306/dsp_development";
		//String classforname = "com.ddtek.jdbc.sqlserver.SQLServerDriver";
		String classforname = "com.mysql.jdbc.Driver";
		try {
			Class.forName(classforname);
			conn = DriverManager.getConnection(url ,username,password);
			System.out.println("Connect Success!");
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	public static Connection getConnection()
	{
		new DBConnection();
		return conn;
	}

	public void testDate(){
		System.out.println(new Date(System.currentTimeMillis()).toString());
	}

	public static void main(String[] args) {

		DBConnection b = new DBConnection();
		b.testDate();
		/*for (int i = 1 ; i < 10000 ; i++){
			b.aa();
		}*/
//		PreparedStatement pstmt = null;
//		ResultSet rset = null;
//		Connection conn = DBConnection.getConnection();
//		try {
//			for (int i = 1 ; i <  10000 ; i++) {
//				pstmt = conn.prepareStatement("select 1");
//				rset  = pstmt.executeQuery();
//				rset.close();
//				pstmt.close();
//				pstmt = conn.prepareStatement("select 2");
//				rset  = pstmt.executeQuery();
//				rset.close();
//				pstmt.close();
//				//System.out.println(i);
//			}
//			System.out.println("a");
//		} catch (SQLException e) {
//			e.printStackTrace();
//		}
	}

	public void aa(){
		Connection  conn = DBConnection.getConnection();
		PreparedStatement pstmt = null;
		try {
			 conn.setAutoCommit(false);
			pstmt = conn.prepareStatement("insert into hr_kindred (cids , kindred_code , kindred_note ,is_share , company_id) values (" +
					"'0000002557','Q01','1','Y','0000000000001000')");
		    pstmt.executeUpdate();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
}
